package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Department;
import cn.imvc.app.models.DepartmentModel;
import cn.imvc.app.models.PositionDepartmentModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class PositionDepartmentControllerImpl implements
		PositionDepartmentController {
	public String positions;
	public String departments;
	
	public int id;
	public int[] departmentid;
	public void setId(int id) {
		this.id = id;
	}
	@Autowired
	private PositionDepartmentModel positionDepartmentModel;
	@Autowired
	private DepartmentModel departmentModel;
	public String index() {
		positions=positionDepartmentModel.getPositions();
		return "position-department/index";
	}

	public String show() {
		departments=positionDepartmentModel.getDepartmentTree(id);
		return "position-department/show";
	}

	public String create() {
		Set<Department> departments=new HashSet<Department>();
		if(departmentid!=null)
			for (int did : departmentid) {
				departments.add(departmentModel.get(did));
			}
		positionDepartmentModel.savePositionDepartment(id, departments);
		return Render.json(new DialogBean("200", "保存成功","rosition-department","closeCurrent"));
	}
	

}
